
<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip">输入任意用户名和密码即可</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from "_c/login-form";
import { mapActions } from "vuex";
export default {
  components: {
    LoginForm
  },
  methods: {
    ...mapActions(["handleLogin", "setTime", "handleTime"]),
    handleSubmit({ userName, password }) {
      this.$Loading.start();
      this.handleLogin({ userName, password }).then(res => {
        if (res.data.code === 0) {
          this.$Loading.finish();
          this.$Message.success("登录成功");
          this.$router.push({
            name: this.$config.homeName
          });
        } else if (res.data.code == 1010) {
          this.$Loading.error();
          this.$Message.error("登录失败，用户名或密码错误！");
          return;
        } else {
          this.$Loading.error();
          this.$Message.error("登录失败");
          return;
        }
      });
    }
  },
  created() {
    this.$store.commit("setTagNavList", []);
  }
};
</script>

<style lang="less">
@import "./login.less";
.demo-spin-icon-load {
  animation: ani-demo-spin 1s linear infinite;
}
</style>
